package cn.ewsio.dbtool.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class DbController extends Controller {

	public void getAllSchemaName() {
		List<Record> records = Db.find("SELECT SCHEMA_NAME FROM information_schema.SCHEMATA");
		renderJson(records);
	}
	
	public void getTblsBySchemaName() {
		String schema = get("schema");
		List<Record> records = Db.find("select TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES where TABLE_SCHEMA=?", schema);
		renderJson(records);
	}
	
	public void getColumnsBySchemaNameAndTbl() {
		String schema = get("schema");
		String table = get("table");
		List<Record> records = Db.find("select COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT,IS_NULLABLE,COLUMN_TYPE,COLUMN_COMMENT FROM information_schema.COLUMNS where TABLE_SCHEMA=? and TABLE_NAME=?", schema, table);
		renderJson(records);
	}
}
